package com.LeeCode;

/**
 * 计算布尔二叉树的值
 */

public class Code2331 {
    public static void main(String[] args) {
        Integer[] arr = {2, 1, 3, null, null, 0, 1};
        TreeNode root = Utils.buildTree(arr);
        System.out.println(new Code2331().evaluateTree(root));
    }

    public boolean evaluateTree(TreeNode root) {
        if (root.left == null) return root.val == 1;

        if (root.val == 2) {
            return evaluateTree(root.left) || evaluateTree(root.right);
        } else {
            return evaluateTree(root.left) && evaluateTree(root.right);
        }
    }
}
